package com.situ.water_Invoice.controller;


import com.situ.water_Invoice.mapper.IvIninvoiceMapper;
import com.situ.water_Invoice.mapper.IvInvoiceMapper;
import com.situ.water_Invoice.mapper.IvOutinvoiceMapper;
import com.situ.water_Invoice.pojo.*;
import com.situ.water_Invoice.service.IvIninvoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Angel
 * @since 2020-12-01
 */
@RestController
//@RequestMapping("/iv-outinvoice")
public class IvOutinvoiceController {
    @Autowired
    IvOutinvoiceMapper mapper;
    @Autowired
    IvIninvoiceMapper ivIninvoiceMapper;
    @Autowired
    IvInvoiceMapper ivInvoiceMapper;

    @ResponseBody
    @RequestMapping("/FPCK")//发票出库情况查询
    public List<FPCK> FPCK(){
        List<FPCK> list = mapper.FPCK();
        list.forEach(System.out::println);
        return list;
    }

    @ResponseBody
    @RequestMapping("/FPSF")//发票收费情况查询
    public List<FPSF> FPSF(){
        List<FPSF> list = mapper.FPSF();
        list.forEach(System.out::println);
        return list;
    }

    //发票出库_获取发票类型
    @ResponseBody
    @RequestMapping("/FPCK_FPLX")
    public String FPCK_FPLX(IvIninvoice ivIninvoice) {
        IvIninvoice type = ivIninvoiceMapper.type(ivIninvoice.getStartNo(), ivIninvoice.getEndNo());
        System.out.println(type.getInvoiceType());
        System.out.println(type.getId());
        String str=null;
        if (type == null) {
            str="true";
        } else {
            if (type.getInvoiceType() == 0) {
                System.out.println("普通发票");
                str="普通发票";
            }
            if (type.getInvoiceType() == 1) {
                System.out.println("增值税发票");
                str="增值税发票";
            }
            System.out.println("false");
        }
        str +=","+ type.getId();
        return str;
    }


    //比较发票号码是否存在  --  存在代表已出库
    @PostMapping("/iv-out-StartNo")
    public int bj(String StartNo){
        System.out.println("我进来了"+StartNo);
        IvOutinvoice ivout = mapper.queryId(StartNo);
        //System.out.println(ivout.getId());
        int str = 0;
        if(ivout == null){
            str=1;
        }else{
            str=0;
        }
        return str;//ResponseData.ok().putDataValue("list", list);
    }


    //出库
    @PostMapping("/iv-outadd")
    public int  addIvOutinvoice(IvOutinvoice ivOutinvoice){
        System.out.println(ivOutinvoice.getStartNo()+"  empid="+ivOutinvoice.getEmpID());
        int add = mapper.addIvOutinvoice(ivOutinvoice);
        if(add>0){
            System.out.println("出库成功！");
        }else{
            System.out.println("出库失败!");
        }
        return add;
    }

    //把id添加到 Iv_Invoice表中
    @PostMapping("/getOutID")
    public int add(){
        IvIninvoice ivinid = mapper.Ivinid();
        System.out.println(ivinid.getId());
        IvInvoice list = ivInvoiceMapper.querynullOutID();
        System.out.println(list.getInvoiceNo());
        ivInvoiceMapper.updateInInvoiceOutID(ivinid.getId(), list.getInvoiceNo());
        int o=0;
        return o;
    }

}

